//
//  StrictElectionCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/16.
//  Copyright © 2020 王洋. All rights reserved.
//
#import "ZZStarView.h"

#import "StrictElectionCell.h"

@interface StrictElectionCell ()

@property (nonatomic, strong) ZZStarView *starView;


@end

@implementation StrictElectionCell

+ (CGFloat)calculateHeight {
    return (TTScreenWidth-20)*0.4956 + 60;
}

- (void)awakeFromNib {
    [super awakeFromNib];

    [self.starBGView addSubview:self.starView];

    [self.starView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    
    [self.collectControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
       
        if (self.StrictElectionCellBlock) {
            self.StrictElectionCellBlock(StrictElectionCellActionType_collect);
        }
    }];
}

- (void)fillCellWithModel:(CommonSellerModule *)model {
    
    self.storeName.text = model.sellerName;
    
    self.favoriteLab.text = [NSString stringWithFormat:@"%ld",model.collectionCount];
    
    self.starView.grade = model.sellerEvaluateStar;

    if (model.sellerEvaluateStar > 0) {
        self.storeStarLab.text = [NSString stringWithFormat:@"%.1f",model.sellerEvaluateStar];
    } else {
        self.storeStarLab.text = @"暂无评分";
    }
    
    if (model.distance > 0) {
        if (model.distance < 1000) {
            self.addressLab.text = [NSString stringWithFormat:@"%.fm|%@",model.distance,model.sellerAddress]; ;
        } else {
            self.addressLab.text = [NSString stringWithFormat:@"%.fkm|%@",model.distance/1000,model.sellerAddress]; ;
        }
    } else {
        self.addressLab.text = model.sellerAddress;
    }
    
    if (model.coverPaths.count > 0) {
        [self.storeMainImageView sd_setImageWithURL:[NSURL URLWithString:model.coverPaths.firstObject.url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    } else {
        [self.storeMainImageView sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    }
    
    self.storeQualityTag.hidden = YES;
    if (model.sellerQualityAuthentication.applyType == 1) {
        self.storeQualityTag.hidden = NO;
        [self.storeQualityTag setImage:[UIImage imageNamed:@"pingpairenzheng"]];
        self.qualityIconWidth.constant = 55;

    } else if (model.sellerQualityAuthentication.applyType == 2) {
        self.storeQualityTag.hidden = NO;
        [self.storeQualityTag setImage:[UIImage imageNamed:@"pingzhirenzheng"]];
        self.qualityIconWidth.constant = 55;

    } else {
        self.storeQualityTag.hidden = YES;
        self.qualityIconWidth.constant = CGFLOAT_MIN;
    }
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self.storeMainImageView pp_clipCorners:UIRectCornerAllCorners radius:8];
    });
    
}

- (ZZStarView *)starView {
    
    if (!_starView) {

        _starView = [[ZZStarView alloc] initWithImage:[UIImage imageNamed:@"daxing_nor"] selectImage:[UIImage imageNamed:@"daxing_sel"] starWidth:12 starHeight:12 starMargin:2 starCount:5 callBack:^(CGFloat userGrade, CGFloat finalGrade) {
        }];
        //默认值, 可以不写, 用户可选分值范围是0.5的倍数.(建议在设置分值之前确定此值)
        _starView.sublevel = 0.5;
        //设置分值, 可以不写, 默认显示0分.(self.params是UIViewController在ZZRouter中扩展的属性, 包含了所有参数)
        _starView.grade = 0.0;
        //最小值, 默认0.5可以不写, 用户可以设置的最低分值.
        _starView.miniGrade = 0;
        _starView.frame = CGRectMake(0, 0, 70, 14);

    }
    return _starView;
}

@end
